<template>
  <!-- 头部整体盒子 -->
  <div id="header" class="container-fuild" :style="{background: '#1363c6'}">

    <!-- 电脑导航 -->
    <div class="header-nav container hidden-xs">
      <!-- 导航logo -->
      <div class="header-nav-logo">
<!--        <div class="head-img" @click="toIndex" :style="{-->
<!--          background: scrollHeight > 0 ? 'url(' + ImgData[1] + ') no-repeat' : 'url(' + ImgData[0] + ') no-repeat',-->
<!--          'background-size': scrollHeight > 0 ? '100% 100%'  : '100% 100%' }"></div>-->
        <div>科技成果文库</div>
      </div>
      <!-- 导航内容 -->
      <ul class="header-nav-wrapper">
        <li
          v-for="(item,index) in navList"
          :key="index"
          :class="index==navIndex?'active':''"
          @click="navClick(index,item.colL1Name)"
        >
          <router-link :to="item.path" :style="{color:  '/' + routerName  == item.path ? '#FFFFFF' : 'rgba(255, 255, 255, .7)' }">
            {{item.colL1Name}}
            <span v-if="item.casColumnL2List.length>0" class="glyphicon glyphicon-menu-down"></span>
            <i class="underline"></i>
          </router-link>
          <dl v-if="item.casColumnL2List.length>0">
            <dt v-for="(i,n) in item.casColumnL2List" :key="n">
              <div @click="childClick(i.colL2Content)">{{i.colL2Name}}</div>
            </dt>
          </dl>
        </li>
      </ul>
    </div>
  </div>
</template>
<script>
import {getNavLevel} from "../api/api";

export default {
  name: "Header",
  data() {
    return {
      ImgData: [

      ],
      scrollHeight: 0,
      navIndex: sessionStorage.getItem('navIndex') ? sessionStorage.getItem('navIndex') : 0,
      menuName: "首页",
      menuClass: "glyphicon glyphicon-menu-down",
      routerName: '',
      navList: []
    };
  },
  watch:{
    '$route':function(){
      let that = this
      console.log('watch里面````````', that.$route.name);
      that.routerName = that.$route.name == 'home' ?  '' : that.$route.name
    }
  },
  mounted() {
    console.log('sss', this.$route.path)
    //监听滚动
    window.addEventListener("scroll", this.scrollFn);
    getNavLevel().then(res => {
      this.navList.push({
        colL1Name: "首页",
        path: "/",
        casColumnL2List: []
      },)
      this.navList = this.navList.concat(res.data.data)
      this.navList.forEach((item, idx) => {
        if (idx != 0) {
          item.path = '/' + idx
        }
      })
      // this.navList[1].path = '/technologyintroduction'  // 调试跳转列表用，后面需要注释
    }).catch(err => {
      console.log(err)
    })
  },
  beforeDestroy() {
    // 移除监听
    window.removeEventListener("scroll", this.scrollFn);
  },
  methods: {
    toIndex () {
      this.$router.push({
        name: 'home',
        query: {}
      })
    },
    //监听滚动
    scrollFn() {
      // 获取窗口高度wh，滚动出去的长度st，文档的长度doch
      let wh = window.innerHeight || document.documentElement.height || document.body.height;
      let st = document.documentElement.scrollTop || document.body.scrollTop;
      this.scrollHeight = st
      let doch = document.documentElement.scrollHeight || document.body.scrollHeight;
      if (wh + st >= doch) {
        console.log("触底了");
      }
    },
    childClick(item) {
      this.$router.push({
        name: 'prodDetail',
        query: {
          detail: item,
          isShow: 1
        }
      })
    },
    navClick(index, name) {
      this.navIndex = index;
      sessionStorage.setItem('navIndex',index)
      this.menuName = name;
    },
    menuClick() {
      if (this.menuClass == "glyphicon glyphicon-menu-down") {
        this.menuClass = "glyphicon glyphicon-menu-up";
      } else {
        this.menuClass = "glyphicon glyphicon-menu-down";
      }
    }
  }
};
</script>
<style scoped>
/* 顶部 */
.header-nav{
  //width: 1320px;
  max-width: unset!important;
  margin: 0 auto;
}
#header {
  width: 100%;
  background: hsla(0,0%,100%,.1);
  transition: background .3s;
  /*transition: all ease 0.6s;*/
  position: fixed;
  top: 0;
  left: 0;
  z-index: 999999;
}
/*#header:hover{*/
/*  background: #FFFFFF!important;*/
/*}*/
/*#header:hover .header-nav .header-nav-wrapper > li > a {*/
/*  color: #000000!important;*/
/*}*/
/*#header:hover .header-nav .header-nav-logo .head-img {*/
/*  background: url("../assets/img/icon-active.png") no-repeat !important;*/
/*  background-size: 100% 100%!important;*/
/*  width: 124px;*/
/*  height: 50px;*/
/*  position: absolute;*/
/*  top: 0;*/
/*  left: 0;*/
/*  right: 0;*/
/*  bottom: 0;*/
/*  margin: auto;*/
/*  cursor: pointer;*/
/*}*/
#header .header-top {
  height: 50px;
  color: #fff;
  font-size: 12px;
  line-height: 50px;
  background: #474747;
}
/* 顶部的图标 */
#header .header-top span {
  margin: 0 8px;
}
/* 导航栏 */
#header .header-nav {
  display: flex;
  justify-content: center;
  height: 70px;
}
/* 导航栏logo */
#header .header-nav .header-nav-logo {
  /*width: 124px;*/
  width: 400px;
  height: 70px;
  line-height: 70px;
  float: left;
  position: relative;
  font-size: 30px;
  font-weight: 500;
  color: #FFFFFF;
}
/* 导航栏logo图片 */
#header .header-nav .header-nav-logo .head-img {
  background-size: 100% 100%!important;
  width: 124px;
  height: 50px;
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  margin: auto;
  cursor: pointer;
}
/* 导航栏 导航容器 */
#header .header-nav-fixed .header-nav-wrapper {
  line-height: 50px;
}
#header .header-nav .header-nav-wrapper {
  line-height: 70px;
  float: right;
  margin: 0;
  //max-width: 800px;
}
/* 导航栏 每个导航 */
#header .header-nav .header-nav-wrapper > li {
  width: 150px;
  float: left;
  text-align: center;
  position: relative;
}
/* 导航栏 每个导航下面的 a 链接 */
#header .header-nav .header-nav-wrapper > li > a {
  color: rgba(255, 255, 255, .7);
  font-size: 16px;
  font-family: PingFang SC-Regular, PingFang SC;
  font-weight: 500;
  padding: 15px 0;
  position: relative;
}
/* 导航栏 每个导航下面的 a 链接的下划线 */
#header .header-nav .header-nav-wrapper > li > a > i {
  /*display: block;*/
  /*position: absolute;*/
  /*bottom: -2px;*/
  /*left: 50%;*/
  /*width: 0;*/
  /*height: 2px;*/
  /*opacity: 0;*/
  /*transition: all 0.6s ease;*/
  /*background-color: #1e73be;*/
}
/* 导航栏 每个导航下面的 a 链接的右侧小三角 */
#header .header-nav .header-nav-wrapper > li > a > span {
  /*font-size: 12px;*/
  /*transition: transform ease 0.5s;*/
}
/* 导航栏 每个导航下面的 a 链接 鼠标滑上去的样式 */
#header .header-nav .header-nav-wrapper > li > a:hover {
  color: #FFFFFF!important;
  text-decoration: none;
}
/* 导航栏 每个导航下面的 a 链接 鼠标滑上去下划线的样式 */
#header .header-nav .header-nav-wrapper > li > a:hover .underline {
  opacity: 1;
  width: 100%;
  left: 0;
}
/* 导航栏 每个导航下面的 a 链接 鼠标滑上去三角标的样式 */
#header .header-nav .header-nav-wrapper > li > a:hover span {
  transform: rotate(180deg);
}
/* 导航栏 每个导航下面的 a 链接 鼠标点击后的样式 */
#header .header-nav .header-nav-wrapper > li.active > a {
  /*color: #1e73be;*/
  text-decoration: none;
  /*border-bottom: 2px solid #1e73be;*/
}
/* 导航栏 每个导航下面的二级导航容器 */
#header .header-nav .header-nav-wrapper > li > dl {
  display: none;
  position: absolute;
  width: 124px;
  top: 100%;
  left: 0;
  z-index: 999999;
  background: #fff;
}
/* 导航栏 每个导航下面的二级导航容器的每个导航 */
#header .header-nav .header-nav-wrapper > li > dl > dt {
  width: 100%;
  font-size: 14px;
  height: 40px;
  line-height: 40px;
}
/* 导航栏 每个导航下面的二级导航容器的每个导航 当鼠标滑上时的样式*/
#header .header-nav .header-nav-wrapper > li > dl > dt > a:hover {
  color: #1363c6;
  text-decoration: none;
}
/* 导航栏 滑上一级导航显示二级导航 */
#header .header-nav .header-nav-wrapper > li:hover dl {
  display: block;
}
#header .header-nav .header-nav-wrapper > li > dl > dt:hover {
  cursor: pointer;
  background: rgba(192, 192, 192, 0.2);
  color: #1363c6;
}
@media screen and (max-width: 997px) {
  #header .header-nav-m {
    position: relative;
  }
  /* 导航栏logo容器 */
  #header .header-nav-m .header-nav-m-logo {
    height: 80px;
    position: relative;
  }
  /* 导航栏logo图片 */
  #header .header-nav-m .header-nav-m-logo img {
    width: 95px;
    height: 45px;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    margin: auto;
  }
  /* 导航栏  菜单容器 */
  #header .header-nav-m .header-nav-m-menu {
    color: #fff;
    height: 50px;
    font-size: 20px;
    line-height: 50px;
    background: #474747;
    position: relative;
  }
  /* 导航栏 菜单图标 */
  #header .header-nav-m .header-nav-m-menu-wrapper {
    position: absolute;
    top: 50%;
    right: 20px;
    margin-top: -20px;
    width: 50px;
    height: 40px;
    color: #fff;
    z-index: 999999;
    font-size: 12px;
  }
  /* 导航栏 */
  #header .header-nav-m .header-nav-m-wrapper {
    position: absolute;
    top: 50px;
    left: 0;
    width: 100%;
    background: #474747;
    z-index: 9999999;
  }
  /* 导航栏 每个导航 */
  #header .header-nav-m .header-nav-m-wrapper > li {
    height: 40px;
    line-height: 40px;
    border-bottom: 1px solid #ccc;
  }
  /* 导航栏 每个导航下面的 a 链接 */
  #header .header-nav-m .header-nav-m-wrapper > li > a {
    color: #fff;
    font-size: 15px;
    font-weight: bold;
    padding: 15px 0;
    position: relative;
  }
  /* 导航栏 每个导航下面的 a 链接的右侧小三角 */
  #header .header-nav .header-nav-wrapper > li > a > span {
    font-size: 10px;
  }
}
</style>
